Skip to main content

Risk Module

Overview

The Risk Module is a core logic contract which houses the logic for risk operations across the protocol. It is closely used with the Risk Engine contract which stores the state variables used as part of these computations. Some of the checks performed by the RiskModule include position health checks, liquidation validations, bad debt checks among others.

State Variables

SENTIMENT_POOL_KEY

Sentiment Registry Pool registry key hash

keccak(SENTIMENT_POOL_KEY)

bytes32 public constant SENTIMENT_POOL_KEY = 0x1a99cbf6006db18a0e08427ff11db78f3ea1054bc5b9d48122aae8d206c09728;

SENTIMENT_RISK_ENGINE_KEY

Sentiment Risk Engine registry key hash

keccak(SENTIMENT_RISK_ENGINE_KEY)

bytes32 public constant SENTIMENT_RISK_ENGINE_KEY = 0x5b6696788621a5d6b5e3b02a69896b9dd824ebf1631584f038a393c29b6d7555;

LIQUIDATION_DISCOUNT

The discount on assets when liquidating, out of 1e18

uint256 public immutable LIQUIDATION_DISCOUNT;

BAD_DEBT_LIQUIDATION_DISCOUNT

Asset discount for bad debt liquidation

uint256 public immutable BAD_DEBT_LIQUIDATION_DISCOUNT;

REGISTRY

The upgradeable registry as a part of the 2step initialization process

Registry public immutable REGISTRY;

pool

Sentiment Singleton Pool

Pool public pool;

riskEngine

Sentiment Risk Engine

RiskEngine public riskEngine;

Functions

constructor

Constructor for Risk Module, which should be registered with the RiskEngine

constructor(address registry_, uint256 liquidationDiscount_, uint256 badDebtLiquidationDiscount_);

Parameters

NameTypeDescription
registry_addressThe address of the registry contract
liquidationDiscount_uint256The discount on assets when liquidating, out of 1e18
badDebtLiquidationDiscount_uint256

updateFromRegistry

Updates the pool and risk engine from the registry

function updateFromRegistry() external;

isPositionHealthy

Evaluates whether a given position is healthy based on the debt and asset values

function isPositionHealthy(address position) public view returns (bool);

getRiskData

Fetch risk-associated data for a given position

function getRiskData(address position) external view returns (uint256, uint256, uint256);

Parameters

NameTypeDescription
positionaddressThe address of the position to get the risk data for

Returns

NameTypeDescription
<none>uint256totalAssetValue The total asset value of the position
<none>uint256totalDebtValue The total debt value of the position
<none>uint256minReqAssetValue The minimum required asset value for the position to be healthy

validateLiquidation

Used to validate liquidator data and value of assets seized

function validateLiquidation(
address position,
DebtData[] calldata debtData,
AssetData[] calldata assetData
) external view;

Parameters

NameTypeDescription
positionaddressPosition being liquidated
debtDataDebtData[]The debt data for the position
assetDataAssetData[]The asset data for the position

validateBadDebt

Verify if a given position has bad debt

function validateBadDebt(address position) external view;

getDebtValueForPool

Gets the ETH debt value a given position owes to a particular pool

function getDebtValueForPool(address position, uint256 poolId) public view returns (uint256);

getTotalDebtValue

Gets the total debt owed by a position in ETH

function getTotalDebtValue(address position) public view returns (uint256);

getAssetValue

Gets the ETH value for a particular asset in a given position

function getAssetValue(address position, address asset) public view returns (uint256);

getTotalAssetValue

Gets the total ETH value of assets in a position

function getTotalAssetValue(address position) public view returns (uint256);

Errors

RiskModule_SeizedTooMuch

Value of assets seized by the liquidator exceeds liquidation discount

error RiskModule_SeizedTooMuch(uint256 seizedValue, uint256 maxSeizedValue);

RiskModule_UnsupportedAsset

Position contains an asset that is not supported by a pool that it borrows from

error RiskModule_UnsupportedAsset(address position, uint256 poolId, address asset);

RiskModule_ZeroMinReqAssets

Minimum assets required in a position with non-zero debt cannot be zero

error RiskModule_ZeroMinReqAssets();

RiskModule_LiquidateHealthyPosition

Cannot liquidate healthy positions

error RiskModule_LiquidateHealthyPosition(address position);

RiskModule_NoBadDebt

Position does not have any bad debt

error RiskModule_NoBadDebt(address position);